var express =  require('express');
var bodyParser = require('body-parser');



var app =  express();
// var urlencodeParser = bodyParser.urlencoded({extend:false});
app.use(express.static('public'));
app.use(bodyParser.urlencoded({ extended: true }));
app.get('/',function(req,res){
	console.log('index get ');
	res.send('hello get');
})
app.post('/',function(req,res){
	console.log('index post');
	res.send("hello post");
})

app.get('/hello',function(req,res){
	console.log('hello get ');
	res.send('hello get');
})

app.get('/index',function(req,res){
	res.sendFile(__dirname+'/'+'index.html');
})

app.get('/process_get',function(req,res){
	response = {
		first_name:req.query.first_name,
		last_name:req.query.last_name
	}
	console.log(response);
	res.end(JSON.stringify(response));
})


app.post('/process_post',urlencodeParser,function(req,res){
	response = {
		first_name:req.body.first_name,
		last_name:req.body.last_name
	}
	console.log(response);
	res.end(JSON.stringify(response));
})

var server =  app.listen(8000,function(){

	var host = server.address().address;
	var port = server.address().port;
	console.log('server running on http://%s:%s',host,port);
})